﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;

namespace Modele
{
    /* 
     * Contient les fonctions spécialisés sur les notes
     */
    
    public partial class Note
    {


        public float toFreq()
        {

            float res = 0;

            switch (this.note)
            {

                case NoteEn.C:
                    
                    if (alteration == Alteration.No || alteration == Alteration.Becard) { res = 16.25f; break; }
                   // ATTENTION DO BEMOL N'existe pas
                  // if (alteration == Alteration.Bemol) { res = 19.45f; break; }
                    if (alteration == Alteration.Diese) { res = 17.32f; break; }break;
                   

                case NoteEn.D:

                    if (alteration == Alteration.No || alteration == Alteration.Becard) { res = 18.35f;; break; }
                    if (alteration == Alteration.Bemol) { res = 17.32f; ; break; }
                    if (alteration == Alteration.Diese) { res = 19.45f; break; }break;
                   
                    

                case NoteEn.E:
                    if (alteration == Alteration.No || alteration == Alteration.Becard) { res = 20.60f; break; }
                    if (alteration == Alteration.Bemol) { res = 19.45f; break; }
                    if (alteration == Alteration.Diese) { res = 21.83f; break; }break;
                   

                case NoteEn.F:
                    if (alteration == Alteration.No || alteration == Alteration.Becard) { res = 21.83f; break; }
                    if (alteration == Alteration.Bemol) { res = 20.60f; break; }
                    if (alteration == Alteration.Diese) { res = 23.12f; break; }break;
                  
                case NoteEn.G: 
                    if (alteration == Alteration.No || alteration == Alteration.Becard) { res = 24.50f; break; }
                    if (alteration == Alteration.Bemol) { res = 23.12f; break; }
                    if (alteration == Alteration.Diese) { res = 25.96f; break; }break;
                 


                case NoteEn.A: 
                    
                    if (alteration == Alteration.No || alteration == Alteration.Becard) { res = 27.50f; break; }
                    if (alteration == Alteration.Bemol) { res = 25.96f; break; }
                    if (alteration == Alteration.Diese) { res = 29.14f; break; }break;
                  

                case NoteEn.B: 
                    if (alteration == Alteration.No || alteration == Alteration.Becard) { res = 30.87f; break; }
                    if (alteration == Alteration.Bemol) { res = 29.14f; break; }
                    if (alteration == Alteration.Diese) { res = 32.70f; break; }break;
                  
            }

            switch (this.octave)
            {
                case 0: break;

                case 1: res = res * 2; break;
                case 2: res = res * 4; break;
                case 3: res = res * 8; break;
                case 4: res = res * 16; break;
                case 5: res = res * 32; break;
                case 6: res = res * 64; break;
                case 7: res = res * 128; break;
                case 8: res = res * 256; break;
                case 9: res = res * 512; break;
            }

            return res;

        }




        public void ajouterNote(Note n)
        {
            noteAccord.Add(n);
        }

        public void supprimerNote(int pos)
        {
            noteAccord.RemoveAt(pos);
        }


/*
        public void augmenterDemiTon()
        {
            switch (this.note)
            {
                case NoteEn.C:
                    if (this.alteration == Alteration.No) { this.alteration = Alteration.Diese; }
                    else { this.alteration = Alteration.No; this.note = NoteEn.D; }
                    break;
                case NoteEn.D:
                    if (this.alteration == Alteration.No) { this.alteration = Alteration.Diese; }
                    else { this.alteration = Alteration.No; this.note = NoteEn.E; }
                    break;
              
                case NoteEn.E:
                    this.alteration = Alteration.No; this.note = NoteEn.F;
                    break;
                case NoteEn.F:
                    if (this.alteration == Alteration.No) { this.alteration = Alteration.Diese; }
                    else { this.alteration = Alteration.No; this.note = NoteEn.G; }
                    break;
                case NoteEn.G:
                    if (this.alteration == Alteration.No) { this.alteration = Alteration.Diese; }
                    else { this.alteration = Alteration.No; this.note = NoteEn.A; }
                    break;
                case NoteEn.A:
                    if (this.alteration == Alteration.No) { this.alteration = Alteration.Diese; }
                    else { this.alteration = Alteration.No; this.note = NoteEn.B; }
                    break;
                case NoteEn.B:
                    if (this.octave < 9) { this.alteration = Alteration.No; this.note = NoteEn.D; this.octave++; }
                    else { Console.WriteLine("operator++ erreur: limite des octaves"); }
                    break;
            }

            this.freqHz = this.toFreq();

        }*/

        /*fonction qui calcule la note en fonction de la position sur le manche (case, corde)*/

        /*public void calculerNote(Tablature tab)
        {
            //  this.note = tab.accordage.ElementAt(this.tablatureInfos.numCorde);
            //   this.alteration = tab.accordage.ElementAt(this.tablatureInfos.numCorde).;


            for (int i = 0; i < tablatureInfos.numCase; i++)
            {
                this.augmenterDemiTon();
            }

        }*/


        // Retourne la liste de toutes les notes possibles
        public static List<Note> NotesPossibles()
        {
            List<Note> notesPossibles = new List<Note>();

            for (int cptOctave = 0; cptOctave < 10; cptOctave++)
            {

                notesPossibles.Add(new Note(Note.NoteEn.C, Note.Alteration.No, cptOctave));
                notesPossibles.Add(new Note(Note.NoteEn.C, Note.Alteration.Diese, cptOctave));

                notesPossibles.Add(new Note(Note.NoteEn.D, Note.Alteration.Bemol, cptOctave));
                notesPossibles.Add(new Note(Note.NoteEn.D, Note.Alteration.No, cptOctave));
                notesPossibles.Add(new Note(Note.NoteEn.D, Note.Alteration.Diese, cptOctave));

                notesPossibles.Add(new Note(Note.NoteEn.E, Note.Alteration.Bemol, cptOctave));
                notesPossibles.Add(new Note(Note.NoteEn.E, Note.Alteration.No, cptOctave));
               

                notesPossibles.Add(new Note(Note.NoteEn.F, Note.Alteration.No, cptOctave));
                notesPossibles.Add(new Note(Note.NoteEn.F, Note.Alteration.Diese, cptOctave));

                notesPossibles.Add(new Note(Note.NoteEn.G, Note.Alteration.Bemol, cptOctave));
                notesPossibles.Add(new Note(Note.NoteEn.G, Note.Alteration.No, cptOctave));
                notesPossibles.Add(new Note(Note.NoteEn.G, Note.Alteration.Diese, cptOctave));


                notesPossibles.Add(new Note(Note.NoteEn.A, Note.Alteration.Bemol, cptOctave));
                notesPossibles.Add(new Note(Note.NoteEn.A, Note.Alteration.No, cptOctave));
                notesPossibles.Add(new Note(Note.NoteEn.A, Note.Alteration.Diese, cptOctave));
               

                notesPossibles.Add(new Note(Note.NoteEn.B, Note.Alteration.Bemol, cptOctave));
                notesPossibles.Add(new Note(Note.NoteEn.B, Note.Alteration.No, cptOctave));

            }

            return notesPossibles;

        }


        /* A finir */
        public void calculerDuree(int tempo)
        {
            switch (rythme)
            {

                /* TYPE RYTHMIQUE NOTE */
                case TypeRytmique.Ronde:

                    if (pointure == Pointure.No)
                    {
                    }
                    if (pointure == Pointure.Pointe)
                    {
                    }
                    if (pointure == Pointure.DoublePointe)
                    {
                    }

                    break;

                case TypeRytmique.Blanche:
                    if (pointure == Pointure.No)
                    {
                    }
                    if (pointure == Pointure.Pointe)
                    {
                    }
                    if (pointure == Pointure.DoublePointe)
                    {
                    }

                    break;

                case TypeRytmique.Noire:
                    if (pointure == Pointure.No)
                    {
                    }
                    if (pointure == Pointure.Pointe)
                    {
                    }
                    if (pointure == Pointure.DoublePointe)
                    {
                    }

                    break;

                case TypeRytmique.Croche:
                    if (pointure == Pointure.No)
                    {
                    }
                    if (pointure == Pointure.Pointe)
                    {
                    }
                    if (pointure == Pointure.DoublePointe)
                    {
                    }

                    break;

                case TypeRytmique.TripleCroche:
                    if (pointure == Pointure.No)
                    {
                    }
                    if (pointure == Pointure.Pointe)
                    {
                    }
                    if (pointure == Pointure.DoublePointe)
                    {
                    }

                    break;

                case TypeRytmique.QuadrupleCroche:
                    if (pointure == Pointure.No)
                    {
                    }
                    if (pointure == Pointure.Pointe)
                    {
                    }
                    if (pointure == Pointure.DoublePointe)
                    {
                    }

                    break;


                /* TYPE RYTHMIQUE SILENCE */



                case TypeRytmique.Pause:
                    if (pointure == Pointure.No)
                    {
                    }
                    if (pointure == Pointure.Pointe)
                    {
                    }
                    if (pointure == Pointure.DoublePointe)
                    {
                    }
                    break;


                case TypeRytmique.DemiPause:
                    if (pointure == Pointure.No)
                    {
                    }
                    if (pointure == Pointure.Pointe)
                    {
                    }
                    if (pointure == Pointure.DoublePointe)
                    {
                    }
                    break;


                case TypeRytmique.Soupir:
                    if (pointure == Pointure.No)
                    {
                    }
                    if (pointure == Pointure.Pointe)
                    {
                    }
                    if (pointure == Pointure.DoublePointe)
                    {
                    }
                    break;

                case TypeRytmique.DemiSoupir:
                    if (pointure == Pointure.No)
                    {
                    }
                    if (pointure == Pointure.Pointe)
                    {
                    }
                    if (pointure == Pointure.DoublePointe)
                    {
                    }

                    break;

                case TypeRytmique.QuartSoupir:
                    if (pointure == Pointure.No)
                    {
                    }
                    if (pointure == Pointure.Pointe)
                    {
                    }
                    if (pointure == Pointure.DoublePointe)
                    {
                    }
                    break;

                case TypeRytmique.HuitiemeSoupir:
                    if (pointure == Pointure.No)
                    {
                    }
                    if (pointure == Pointure.Pointe)
                    {
                    }
                    if (pointure == Pointure.DoublePointe)
                    {
                    }
                    break;

                case TypeRytmique.SeiziemeSoupir:
                    if (pointure == Pointure.No)
                    {
                    }
                    if (pointure == Pointure.Pointe)
                    {
                    }
                    if (pointure == Pointure.DoublePointe)
                    {
                    }
                    break;
            }

        }
    }

    
}
